package j_util.sorters;

import java.util.Comparator;
import java.util.List;

public class SelectionSort extends Sort {

    public <T> void sort(List<T> list, int left, int right, Comparator<T> c) {
        resetVariables();
        time = System.currentTimeMillis();
        for (int i = left; i < right; i++) {
            int min = i;
            for (int j = i + 1; j <= right; j++)
                if (less(list.get(j), list.get(min), c)) {
                    min = j;
                }
            exchange(list, i, min);
        }
        time = System.currentTimeMillis() - time;
    }

    public String getName() {
        return "SelectionSort";
    }

    public <T> void sort(List<T> list, Comparator<T> comparator) {
        int left = 0;
        int right = list.size();
        sort(list, left, right - 1, comparator);
    }
}
